<template>
  <div class="login-container">
    <el-form ref="loginForm" :model="loginForm" class="login-form" autocomplete="on" label-position="left">
      <div class="title">线上校园后台管理系统</div>
      <el-form-item prop="username" class="mb16">
        <div style="display: flex; align-items:center;">
          <span class="svg-container">
            <div class="iconfont icon-shurukuang_zhanghao"></div>
          </span>
          <el-input v-model="loginForm.username" placeholder="请输入账号" type="text" autocomplete="on" clearable />
        </div>
      </el-form-item>
      <el-form-item prop="password" class="mb16">
        <div style="display: flex; align-items:center;">
          <span class="svg-container">
            <div class="iconfont icon-mimasuo"></div>
          </span>
          <el-input v-model="loginForm.password" placeholder="请输入密码" @keyup.enter.native="handleLogin" show-password />
        </div>
      </el-form-item>
      <div class="flex-center">
        <el-radio label="记住密码" v-model="loginForm.loginCheck" class="agree-radio"></el-radio>
      </div>
      <b-button-new style="width:100% !important; height: 40px !important;" class="loginBtn theme-btn-solid" @click.native.prevent="handleLogin" text="登录"></b-button-new>
    </el-form>
    <div class="icp">© 2024 <a href="http://beian.miit.gov.cn/" target="_blank"> 渝ICP备2024026677号</a></div>
  </div>
</template>

<script>
import store from '@/store/index'
export default {
  name: "Login",
  data() {
    return {
      loginForm: {
        username: "", // 用户名
        password: "", // 密码
        loginCheck: false,
      },
      loginRules: {
        username: [{ required: true, message: "请输入账号", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  created() {
    // window.addEventListener('storage', this.afterQRScan)
    localStorage.setItem("isAddRoutes", false);
    // localStorage.removeItem("permission");
    // localStorage.removeItem("p");
    store.dispatch('user/SET_IS_ADD_ROUTES', false)
  },
  mounted() {
    var loginAccount = JSON.parse(localStorage.getItem("loginAccount"));
    if (loginAccount != undefined) {
      this.loginForm = loginAccount;
    }
  },
  methods: {
    handleLogin() {
      const { username, password ,loginCheck} = this.loginForm
      if (!username || !password) {
        this.$message.error('请先输入账号密码')
        return
      }
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          console.log(this.loginForm,1212);
          this.$store.dispatch("user/login", this.loginForm).then((path) => {
            if (loginCheck) { // 记住账号密码
              localStorage.setItem('loginAccount', JSON.stringify({ username, password }))
            }
            this.$router.replace(path)
          }) .catch(() => { });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #283443;
$light_gray: #fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  .el-form-item__content {
    line-height: 26px;
  }
  .el-input {
    display: inline-block;
    height: 40px;
    width: 90%;
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: #999;
      height: 40px;

      // caret-color: $cursor;

      &:-webkit-autofill {
        background: #fff !important;
        -webkit-text-fill-color: #999 !important;
      }
    }
    // 修改input的默认样式
    input:-webkit-autofill,
    textarea:-webkit-autofill,
    select:-webkit-autofill {
      transition: background-color 50000s ease-in-out 0s; /*背景色透明  生效时长  过渡效果  启用时延迟的时间*/
    }
  }

  .el-form-item {
    border: 1px solid #d9d9d9;
    background: #fff;
    border-radius: 5px;
    color: #999;
  }
  .loginBtn {
    width: 100%;
    background: #17b4a4;
    border-radius: 4px;
    height: 40px;
    border: none !important;
  }
}
</style>

<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background: url('https://djtravel2.obs.cn-east-3.myhuaweicloud.com/medical_dev/1710164796992/a676af60-586a-4d11-af5e-77b2d876bcdc.jpg') no-repeat;
  background-size: 100% ;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  .login-form {
    position: relative;
    width: 400px;
    max-width: 100%;
    height: 360px;
    padding: 45px 32px;
    border-radius: 16px;
    overflow: hidden;
    background: #f5f5f5;
  }

  .svg-container {
    height: 40px;
    padding: 0 5px 0 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title {
    font-size: 20px;
    color: #000;
    font-weight: bold;
    line-height: 28px;
    text-align: center;
    margin-bottom: 32px;
  }
  .flex-center{
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
    .loginRadio{
      margin-bottom: 0;
    }
  }
  @media only screen and (max-width: 470px) {
    .thirdparty-button {
      display: none;
    }
  }
}
.el-icon-close{
  position:absolute;
  top:21px;
  right:21px;
  font-size:24px;
  cursor: pointer;
}
.findText{
  color: rgba(0,0,0,0.45);
  font-size:12px;
  line-height: 20px;
  margin-bottom:32px;
  span{
    display:block;
  }
}

.findPasswordItem{
  position:relative;
  .svg-container{
    width:60px;
  }
  .userPhone{
    position:absolute;
    top:0px;
    left:25px;
    color: rgba(0,0,0,0.85);
    margin-left:8px;
  }
  
  input{
    padding-left:0px !important;
  }
}
.codePhone{
  .code{
    border:none;
    color:#0969DB;
  }
  .el-button:hover{
    background:none;
  }
  
}
.tabListPassword{
  justify-content:flex-start !important;
  .tab-item{
    margin-right:40px;
  }
}

.icp{
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translate(-50%, 0);
  >a:hover{
    color: #0969DB;
  }
}
</style>
